<template>
  <body id="poster">
    <el-form class="login-container" :model="LoginForm" label-position="left" label-width="0px">
      <h3 class="login-title">系统登录</h3>
      <el-form-item label="">
        <el-input type="text" v-model="LoginForm.username" autocomplete="off" placeholder="用户名"/>
      </el-form-item>
      <el-form-item label="">
        <el-input type="password" v-model="LoginForm.password" autocomplete="off" placeholder="密码"/>
      </el-form-item>
      <el-form-item style="width: 100%">
        <el-button type="primary" style="width: 100%" @click="Login">登录</el-button>
      </el-form-item>
    </el-form>
  </body>
</template>

<script>
import {login} from "../api/index.js";
import router from "../router/index.js";
import {setToken} from "../utils/session.js";
export default {
  name :'login',
  data() {
    return {
      LoginForm:{
        username:'',
        password:'',
      }
    }
  },
  mounted() {

  },
  methods:{
    Login(){
      if(this.username===''||this.password==='') {
        alert("用户名或密码不能为空")
      } else {
        login(this.LoginForm).then((res) => {
          //回调信息
          if(res.data.status === '200'){
            setToken('username',this.LoginForm.username)
            setToken('token',res.data.token)
            this.$message({
              message:'登录成功',
              type:'success'
            })
            router.push({path:'/home'});
          }
      })
    }
  }
}
}
</script>

<style scoped>
  #poster{
    background-position: center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
  }
  body{
    margin: 0px;
    padding: 0px;
    background-image: url("./public/loginbackgroundimg.jpg");
  }
  .login-container{
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 300px;
    padding: 35px 35px 15px 35px;
    background: #ffffff;
    border:1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    opacity: 0.8;
  }
  .login-title{
    margin: 0px auto 30px auto;
    text-align: center;
    color: #000000;
  }
</style>